package cn.itnanls.exception;

import cn.itnanls.util.R;
import cn.itnanls.util.ResultCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理器
 * @author Ding
 */
@ControllerAdvice
public class GlobalExceptionResolver {
    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public R businessExceptionHandler(){
        System.out.println("跑到这里啦");
        return R.of( ResultCode.Business_ERROE );
    }
    @ExceptionHandler(ParamIllegalException.class)
    @ResponseBody
    public R ParamIIegalExcetionHandler(ParamIllegalException e){
        e.printStackTrace();
        R r = R.of( ResultCode.ParamIllegal_ERROR );
        r.setOtherMsg( e.getErrors() );
        return  r ;
    }
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R exceptionHandler() {
        return R.of( ResultCode.UNKNOW_ERROR );
    }

}
